home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Chat & Communication / Digsby build 37 / digsby_setup.exe / lib / distutils / version.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2008-10-13  |  4KB  |  118 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. import string
  5. import re
  6. from types import StringType
  7.  
  8. class Version:
  9.     
  10.     def __init__(self, vstring = None):
  11.         if vstring:
  12.             self.parse(vstring)
  13.         
  14.  
  15.     
  16.     def __repr__(self):
  17.         return "%s ('%s')" % (self.__class__.__name__, str(self))
  18.  
  19.  
  20.  
  21. class StrictVersion(Version):
  22.     version_re = re.compile('^(\\d+) \\. (\\d+) (\\. (\\d+))? ([ab](\\d+))?$', re.VERBOSE)
  23.     
  24.     def parse(self, vstring):
  25.         match = self.version_re.match(vstring)
  26.         if not match:
  27.             raise ValueError, "invalid version number '%s'" % vstring
  28.         
  29.         (major, minor, patch, prerelease, prerelease_num) = match.group(1, 2, 4, 5, 6)
  30.         if patch:
  31.             self.version = tuple(map(string.atoi, [
  32.                 major,
  33.                 minor,
  34.                 patch]))
  35.         else:
  36.             self.version = tuple(map(string.atoi, [
  37.                 major,
  38.                 minor]) + [
  39.                 0])
  40.         if prerelease:
  41.             self.prerelease = (prerelease[0], string.atoi(prerelease_num))
  42.         else:
  43.             self.prerelease = None
  44.  
  45.     
  46.     def __str__(self):
  47.         if self.version[2] == 0:
  48.             vstring = string.join(map(str, self.version[0:2]), '.')
  49.         else:
  50.             vstring = string.join(map(str, self.version), '.')
  51.         if self.prerelease:
  52.             vstring = vstring + self.prerelease[0] + str(self.prerelease[1])
  53.         
  54.         return vstring
  55.  
  56.     
  57.     def __cmp__(self, other):
  58.         if isinstance(other, StringType):
  59.             other = StrictVersion(other)
  60.         
  61.         compare = cmp(self.version, other.version)
  62.         if compare == 0:
  63.             if not (self.prerelease) and not (other.prerelease):
  64.                 return 0
  65.             elif self.prerelease and not (other.prerelease):
  66.                 return -1
  67.             elif not (self.prerelease) and other.prerelease:
  68.                 return 1
  69.             elif self.prerelease and other.prerelease:
  70.                 return cmp(self.prerelease, other.prerelease)
  71.             
  72.         else:
  73.             return compare
  74.  
  75.  
  76.  
  77. class LooseVersion(Version):
  78.     component_re = re.compile('(\\d+ | [a-z]+ | \\.)', re.VERBOSE)
  79.     
  80.     def __init__(self, vstring = None):
  81.         if vstring:
  82.             self.parse(vstring)
  83.         
  84.  
  85.     
  86.     def parse(self, vstring):
  87.         self.vstring = vstring
  88.         components = filter((lambda x: if x:
  89. passx != '.'), self.component_re.split(vstring))
  90.         for i in range(len(components)):
  91.             
  92.             try:
  93.                 components[i] = int(components[i])
  94.             continue
  95.             except ValueError:
  96.                 continue
  97.             
  98.  
  99.         
  100.         self.version = components
  101.  
  102.     
  103.     def __str__(self):
  104.         return self.vstring
  105.  
  106.     
  107.     def __repr__(self):
  108.         return "LooseVersion ('%s')" % str(self)
  109.  
  110.     
  111.     def __cmp__(self, other):
  112.         if isinstance(other, StringType):
  113.             other = LooseVersion(other)
  114.         
  115.         return cmp(self.version, other.version)
  116.  
  117.  
  118.